package icasue.reflect.handles.enums;

import lombok.SneakyThrows;
import icasue.reflect.handles.OAble;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2020/11/30 下午12:00
 * @UpdateDate:
 * @Description:
 */
public class EnumO implements OAble {

    public static MethodHandles.Lookup lookup;

    //BASE OPERATOR.
    public static MethodHandle getInstanceByTypeAndName;



    static {
        try {
            Class<?> loadHandleOperate = EnumO.class.getClassLoader().loadClass("icasue.reflect.handles.HandleSupplier");
            EnumO.lookup = (MethodHandles.Lookup)loadHandleOperate.getDeclaredField("methodLookup").get(null);
        }catch (Throwable e){
            throw new RuntimeException("EnumO init error",e);
        }
    }

    static {
        findEnumOperator();
    }

    @SneakyThrows(value = Throwable.class)
    public static void findEnumOperator(){
        getInstanceByTypeAndName = lookup.findStatic(Enum.class,"valueOf", MethodType.methodType(Enum.class,Class.class,String.class));
    }

}
